#include "UnorderedArray.h"
#include "Graph.h"
// Unordered Array implementation of a priority queue

UnorderedArray::UnorderedArray(int size)
{
	_size = 0;
	_edges = new Edge[size];
}

UnorderedArray::~UnorderedArray()
{
	delete[] _edges;
}

void UnorderedArray::clear()
{
	// Delete the queue we only use it once
	_size = 0;
}

void UnorderedArray::insert(Edge *newEdge)
{	
	_edges[_size] = *newEdge;
	_size++;
}

Edge* UnorderedArray::deleteMin()
{	
	float min = 9999;
	int index = -1;		
	
	register int i = 0;
	for (i = 0; i < _size; i++)
		// Consider to min that edge,
		if (_edges[i].cost < min)
		{
			min = _edges[i].cost;
			index = i;
		}		

	// Not found
	if (index == -1)
		return NULL;
	
	return &_edges[index];
}
